<?php
	require '../../include/library.inc.php';
	require '../../include/admin_login.inc.php';
	
	$sql_lang = 'SELECT lang_id,Name,code FROM language WHERE published ';

	if (!isset($_POST['is_submitted'])) {
		$_POST['is_submitted'] = '';
	}
	
	if (!isset($error_message)) {
		$error_message = '';
	}	
//echo serialize($_POST);

$id = $_REQUEST["plan_id"];
$plan_id = $id;

if($_POST["redirect"] || $_SESSION['redirect'] ){
	if($_POST["redirect"]) $redirect = $_POST["redirect"];
	if($_SESSION['redirect']){ 
	$redirect = $_SESSION['redirect'];
	unset($_SESSION['redirect']);
	}
}else{
       $redirect = $_SERVER['HTTP_REFERER'];	
     }	
	 	
	if ($_POST['is_submitted']) {
		
		$error_message = '';
		$redirect = $_POST["redirect"];
    
	
	$result_lang = query($sql_lang);
	while ($row_lang = mysql_fetch_object($result_lang)) {
	
		if (!$_POST['title'][$row_lang->lang_id])  $error_message .= 'Не е въведено Title in '.$row_lang->Name.'<br/>';
		
	
	}
	
	//if (!$_POST['class'])  $error_message .= 'Не е въведен Class<br/>';
		//elseif(!preg_match('/^[0-9A-Za-z\-\_]+$/', $_POST['class'])) $error_message .= 'Въведеният Class е невалиден<br/>';
		
	
	
    if(!$error_message) {
		
		
		$result_lang = query($sql_lang);
		$sql = "DELETE FROM  plan_description WHERE  plan_id = '".$plan_id."'  ";
		query($sql);
		
		while ($row_lang = mysql_fetch_object($result_lang)) {
			
			$sql = "INSERT INTO plan_description
				  (plan_id, lang_id, title, description, destinations)
				VALUES
				  ('".$plan_id."',
				  '".$row_lang->lang_id."', 
				  '".escape($_POST['title'][$row_lang->lang_id])."', 
				  '".escape($_POST['description'][$row_lang->lang_id])."',
				  '".escape($_POST['destinations'][$row_lang->lang_id])."'
				  )";
				 
			query($sql);
			
			
			
		}
		$redirect = $_POST['redirect'];
		
		unset($_POST['redirect']);
		unset($_POST['title']);
		unset($_POST['description']);
		unset($_POST['destinations']);
		unset($plan['is_submitted']);
		unset($plan['redirectForm']);
		unset($plan['published']);
		
		$sql = "UPDATE plans SET plan_data  = '".serialize($_POST)."' , published = '".intval($_POST['published'])."' WHERE plan_id = '".$id."'";
		query($sql);
		
		$_SESSION['message'] .= 'Successfully update!';
         if($redirect){
           redirect($redirect);
		}else{
			$_SESSION['redirect'] = $redirect;
		   redirect(HTML_BASE_ADMIN.'/plan_edit.php?plan_id='.$id);
		   
		   
		}
		
    }

}
  	
	
	head_admin("Edit call plan");
?>


    
<script type="text/javascript" src="<?=HTML_BASE_ADMIN?>js/calendarDateInput.js"></script>
<script type="text/javascript" src="<?=HTML_BASE_ADMIN?>tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
	// General options
	language : "en", 
	mode : "exact",
    elements : "body1,body2,body3,free1,free2,free3",
	theme : "advanced",
	relative_urls : false,
	height : 300,
	
	plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager",

	// Theme options
	theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,formatselect,fontselect,fontsizeselect",
	theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
	theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen,|,image,insertimage",
	theme_advanced_toolbar_location : "top",
	theme_advanced_toolbar_align : "left",
	theme_advanced_statusbar_location : "bottom",
	theme_advanced_resizing : false,

	// Drop lists for link/image/media/template dialogs
	//template_external_list_url : "js/template_list.js",
	external_link_list_url : "js/link_list.php",
	//media_external_list_url : "js/media_list.js",
	//external_image_list_url : "js/blog_image_list.php"
	
});
</script>
		
            <?php if ($error_message) { ?>
			<div class="message red">
				<h3>Erorr!</h3>
				<?=$error_message?>
			</div>
			<?php } ?>
            
             <?php if ($_SESSION['message']) { ?>
    		<div class="message green">
       			 <?=$_SESSION['message']?>
    		</div>
			<?php unset($_SESSION['message']); } ?>
			
            <div class="topbuttons">
            	<a href="<?=$redirect?>">Back</a>
            </div>
			
            <h3>Edit call plan</h3>
			            
            <form id="page_new_form_id" action="<?=$_SERVER['PHP_SELF'].'?'.$_SERVER['QUERY_STRING']?>" method="post" enctype="multipart/form-data">
            <input type="hidden" name="is_submitted" value="1" />
			<input type="hidden" name="redirect" value="<?=$redirect?>" />
             <input id="redirectForm" type="hidden" name="redirectForm" value="" />
            <input type="hidden" name="redirect" value="<?=$redirect?>" />						
					
			
		
	<div id="tabs">
   
        
        	<ul id="tabs-ui">
           
			</ul>
			
			
			<?php
			$tabs="";
			$result_lang = query($sql_lang);
			while ($row_lang = mysql_fetch_object($result_lang)) {
					
				  $tabs.=' <li><a href="'.$_SERVER['PHP_SELF'].'?plan_id='.$plan_id.'#tabs-'.$row_lang->lang_id.'">'.$row_lang->Name.'</a></li>';

					
			if (!$_POST['is_submitted']) {
				
				
					$sql_d = "SELECT *	FROM plan_description
					WHERE
						plan_id = '".$plan_id."'
						AND 
						lang_id = '".$row_lang->lang_id."'
					";
					$result_d = query($sql_d);
					$row_d = mysql_fetch_object($result_d);
					
					$_POST['title'][$row_lang->lang_id] =  $row_d->title;
					$_POST['description'][$row_lang->lang_id] =  $row_d->description;
					$_POST['destinations'][$row_lang->lang_id] =  $row_d->destinations;
					
					
					
					
			}
			
								  
			?>
           
		<div id="tabs-<?=$row_lang->lang_id?>">
           <dl class="clearfix">
                <dt><label class="required">Title in <?=$row_lang->Name?></label></dt>
                <dd><input class="inputbox w500" id="title_<?=$row_lang->lang_id?>" name="title[<?=$row_lang->lang_id?>]" type="text" value="<?=sth($_POST['title'][$row_lang->lang_id])?>" ></dd>
                
                <dt><label>Description in <?=$row_lang->Name?></label></dt>
                <dd><textarea id="body<?=$row_lang->lang_id?>"  class="inputbox" style="width:100%" name="description[<?=$row_lang->lang_id?>]" rows="16"><?=sth($_POST['description'][$row_lang->lang_id])?></textarea></dd>
                
                
                 <dt><label>Free destinations in <?=$row_lang->Name?></label></dt>
                <dd><textarea id="free<?=$row_lang->lang_id?>"  class="inputbox" style="width:100%" name="destinations[<?=$row_lang->lang_id?>]" rows="16"><?=sth($_POST['destinations'][$row_lang->lang_id])?></textarea></dd>
			
            			
		    </dl>
                  
      </div>
            
           <?php
				
			}
			
			
			if(!$_POST['is_submitted']){
				
				$sql = "SELECT 
			
					published,
					plan_data
				FROM
					plans
				WHERE
					plan_id ='".$plan_id."'
				
				";
				
				$result_cat = query($sql);
				$row_cat = mysql_fetch_object($result_cat);
		
		      $_POST  = unserialize($row_cat->plan_data);
			  
			   $_POST['published'] = $row_cat->published;
			}
			
	  		?>
          
           </div>
			
            <br />
<br />
<br />

            
            
			
			<table  border="0">
            <thead>
             <tr >
                <td style="width:160px;"><strong>SERVICE</strong></td>
                <td><strong>VALUES</strong> (Input <strong>-1</strong> for <strong>"Unlimited"</strong>)</td>
              </tr>
            </thead>
              <tr >
                <td><div align="right">Free Calls-Countries:</div></td>
                <td><input class="inputbox w250" name="freecalls" type="text" value="<?=$_POST["freecalls"]?>" /> min</td>
              </tr>
              <tr>
                <td><div align="right">Simultaneous Access	:</div></td>
                <td>
                <select class="inputbox w250" name="simultaneous_access">
                      <option value="1" <?php if($_POST["simultaneous_access"] == 1){ ?>selected="selected"<?php } ?> >yes</option>
                      <option value="0" <?php if($_POST["simultaneous_access"] == 0){ ?>selected="selected"<?php } ?> >no</option>
                </select> 
               </td>
              </tr>
              <tr>
                <td><div align="right">Simultaneous Incoming Calls</div></td>
                <td><input class="inputbox w250" name="simultaneous_incoming" type="text" value="<?=$_POST["simultaneous_incoming"]?>" /></td>
              </tr>
              <tr>
                <td><div align="right">Simultaneous Outgoing Calls</div></td>
                <td><input class="inputbox w250" name="simultaneous_outgoing" type="text" value="<?=$_POST["simultaneous_outgoing"]?>" /></td>
              </tr>
              <tr>
                <td><div align="right">Web Video/Audio Conference Chat 3</div></td>
                <td>
                 <select class="inputbox w250" name="wvacc3">
                      <option value="1" <?php if($_POST["wvacc3"] == 1){ ?>selected="selected"<?php } ?> >yes</option>
                      <option value="0" <?php if($_POST["wvacc3"] == 0){ ?>selected="selected"<?php } ?> >no</option>
                </select> 
                </td>
              </tr>
              <tr>
                <td><div align="right">Web Video Chat Rooms</div></td>
                <td><input class="inputbox w250" name="wvcrooms" type="text" value="<?=$_POST["wvcrooms"]?>" /></td>
              </tr>
              <tr>
                <td><div align="right">Web Video Chat (free video time)</div></td>
                <td><input class="inputbox w250" name="wvcfvt" type="text" value="<?=$_POST["wvcfvt"]?>" /> hour(s)</td>
              </tr>
              <tr>
                <td><div align="right">Web Video/Audio Conference Chat participants</div></td>
                <td><input class="inputbox w250" name="wvaccp" type="text" value="<?=$_POST["wvaccp"]?>" /> participants</td>
              </tr>
              <tr>
                <td><div align="right">Audio Conference </div></td>
                <td>
                <select class="inputbox w250" name="audio_conference">
                      <option value="1" <?php if($_POST["audio_conference"] == 1){ ?>selected="selected"<?php } ?> >yes</option>
                      <option value="0" <?php if($_POST["audio_conference"] == 0){ ?>selected="selected"<?php } ?> >no</option>
                </select> 
                </td>
              </tr>
              <tr>
                <td><div align="right">Conference Rooms	</div></td>
                <td><input class="inputbox w250" name="conference_rooms" type="text" value="<?=$_POST["conference_rooms"]?>" /> rooms</td>
              </tr>
              <tr>
                <td><div align="right">Audio Conference Participants</div></td>
                <td><input class="inputbox w250" name="ac_participants" type="text" value="<?=$_POST["ac_participants"]?>" /> participants</td>
              </tr>
              <tr>
                <td><div align="right">Fax</div></td>
                <td>
                <select class="inputbox w250" name="fax">
                      <option value="1" <?php if($_POST["fax"] == 1){ ?>selected="selected"<?php } ?> >yes</option>
                      <option value="0" <?php if($_POST["fax"] == 0){ ?>selected="selected"<?php } ?> >no</option>
                </select> 
                </td>
              </tr>
              <tr>
                <td><div align="right">Incoming Fax price</div></td>
                <td><input class="inputbox w250" name="incoming_fax" type="text" value="<?=$_POST["incoming_fax"]?>" /> €</td>
              </tr>
              <tr>
                <td><div align="right">Phone Call Recording Minutes</div></td>
                <td><input class="inputbox w250" name="pcrm" type="text" value="<?=$_POST["pcrm"]?>" /> minutes</td>
              </tr>
              <tr>
                <td><div align="right">Voice Mail</div></td>
                <td>
                <select class="inputbox w250" name="voice_mail">
                      <option value="1" <?php if($_POST["voice_mail"] == 1){ ?>selected="selected"<?php } ?> >yes</option>
                      <option value="0" <?php if($_POST["voice_mail"] == 0){ ?>selected="selected"<?php } ?> >no</option>
                </select> 
                </td>
              </tr>
              <tr>
                <td><div align="right">Call Back</div></td>
                <td>
                <select class="inputbox w250" name="call_back">
                      <option value="1" <?php if($_POST["call_back"] == 1){ ?>selected="selected"<?php } ?> >yes</option>
                      <option value="0" <?php if($_POST["call_back"] == 0){ ?>selected="selected"<?php } ?> >no</option>
                </select> 
                </td>
              </tr>
              <tr>
                <td><div align="right"><strong>Period</strong> 1 Mo</div></td>
                <td><input class="inputbox w250" name="p1m" type="text" value="<?=$_POST["p1m"]?>" /> €</td>
              </tr>
              <tr>
                <td><div align="right"><strong>Period</strong> 3 Mo</div></td>
                <td><input class="inputbox w250" name="p3m" type="text" value="<?=$_POST["p3m"]?>" /> €</td>
              </tr>
              <tr>
                <td><div align="right"><strong>Period</strong> 6 Mo</div></td>
                <td><input class="inputbox w250" name="p6m" type="text" value="<?=$_POST["p6m"]?>" /> €</td>
              </tr>
              <tr>
                <td><div align="right"><strong>Period</strong> 12 Mo</div></td>
                <td><input class="inputbox w250" name="p12m" type="text" value="<?=$_POST["p12m"]?>" /> €</td>
              </tr>
              
            </table>

            <dt><input class="checkbox" name="published" id="published" type="checkbox" value="1" <?=(($_POST['published'])?"checked=\"checked\"":"")?> /><label>Published</label></dt>
            </dl>
						
			</form>  
          
          
  <script>
	$(document).ready(function(e) {
           $("#tabs-ui").html('<?=$tabs?>');
	       $( "#tabs" ).tabs();
	  
      });			
  </script>
  
            
<?php
	controls($redirect, "#page_new_form_id");
	foot_admin(); 
?>